#pragma once

#include "stdafx.h"
#include "LogicHost.h"
#include "ExceedRdEvt.h"

int _tmain(int argc, _TCHAR* argv[])
{
    using namespace utils;
    try
    {
        CServiceCmdLine CmdLine;
        try
        {
            CPlugin plugin_dll( CmdLine.GetPluginPath() );
            CLogicHost host(plugin_dll);
            return host.RegisterService(argc, argv);
        }
        catch (std::exception& e)
        {
            if( CServiceCmdLine::execute == CmdLine.GetAction() )
            {
                LPCWSTR pPath = CmdLine.GetPluginPath() ? CmdLine.GetPluginPath() : L""; 
                const std::wstring& refMsg = hc::as_wstring( e.what() );
                WriteEventLog(CLogicHost::GetName(), EVENTLOG_ERROR_TYPE, 
                    CATEGORY_SERVICE_EXECUTING_, EVMSG_LOAD_PLUGIN_, 2, refMsg.c_str(), pPath);
            }
            throw;
        }
    }
    catch (std::exception& e)
    {
        std::cout << e.what() << std::endl;
    }
    return 0;
}